﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using Easy.DAL;

namespace Easy.Operation.Data
{
    public class Plugin : System.Web.HttpApplication
    {
        DataTable plugintable;
        PluginDAL plugindal;
        public Plugin()
        {
            plugindal = new PluginDAL();
            //if (Application["Plugins"] == null)
            //{
            //    plugintable = (DataTable)Application["Plugins"];
            //}
            //else
            //{
            plugintable = plugindal.getPluginTable();
            //    Application["Plugins"] = plugintable;
            //}
        }
        /// <summary>
        /// 根据实体名，触发事件获取对应的Plugin列表
        /// </summary>
        /// <param name="EntityName">实体名</param>
        /// <param name="triggerEvent">触发事件：创建前10 创建后20 更新前30 更新后40 删除前50 删除后60 分派前70 分派后80</param>
        /// <returns></returns>
        public DataRow[] getPlugins(string EntityName, int triggerEvent)
        {
            return plugintable.Select("entityName = '" + EntityName + "' and triggerEvent = " + triggerEvent, "entityName,priority desc");
        }
        public void execSP(string spname, Guid currentrecord, Guid currentuser)
        {
            plugindal.execSP(spname, currentrecord, currentuser);
        }
    }
}
